import { IStageAssetsInfo, Stage } from "babylon-lib/base/stage";
import { ArcRotateCamera} from "@babylonjs/core/Cameras/arcRotateCamera";
import { Scene} from "@babylonjs/core/scene";
import { Camera } from "@babylonjs/core/Cameras/camera";
import { Light } from "@babylonjs/core/Lights/light";
import { RawAssetsUrl, RawData } from "../raw-assets-info";
import { InitializeComponent} from './components/initialize-components';
import { ILoose } from "babylon-lib/tool/utils";
import { AbstractAssetTaskInfo, GLTFMeshTaskInfo} from "babylon-lib/loader/asset-task-info";
import * as Data from '../data/data';
import { CaptureScreen } from 'babylon-lib/highly-coupled-component/capture-screen';
import { DetailView } from "babylon-lib/preset/detail-view";



class DefaultStage extends Stage{

    protected assetTaskInfos(): ILoose<AbstractAssetTaskInfo>|Array<IStageAssetsInfo> {
        return  Object.assign({},[
            new GLTFMeshTaskInfo(RawAssetsUrl.characterFemalModel),
            new GLTFMeshTaskInfo(RawAssetsUrl.characterFemalAnimation),
            new GLTFMeshTaskInfo(RawAssetsUrl.characterHeadModel),
            new GLTFMeshTaskInfo(RawAssetsUrl.characterClothesModel),
            new GLTFMeshTaskInfo(RawAssetsUrl.characterCoatModel),
        ]) as unknown as ILoose<AbstractAssetTaskInfo>; 
    }

    public render(): void {
        this.mainScene.render();
    }

    protected async initializeComponents(scenes:Scene[],cameras:Camera[],lights:Light[]): Promise<void> {
        
        InitializeComponent.initialize(this);
        CaptureScreen.register(this.engine,this.mainCamera,Data.isProduction.value,RawData.appConfig.name);

        this.bindData();
        Data.cameraData.reset(true);
    }

    private bindData():void{
        Data.cameraData.onChange(()=>{
            const camera=this.mainCamera as ArcRotateCamera;
            camera.alpha=Data.cameraAlpha.value;
            camera.beta=Data.cameraBeta.value;
            camera.radius=Data.cameraRadius.value;
            camera.target=Data.cameraTarget.value;
        });
        Data.screenShot.onChange(()=>{
            CaptureScreen.capture(this.engine,this.mainCamera,Data.isProduction.value,RawData.appConfig.name);
        });
    }
    
}

interface IActor{
    detailView?:DetailView,
}

export {DefaultStage};